package com.ruoyi.service.impl;

import com.ruoyi.service.IGrCardService;
import com.ruoyi.web.domain.GrCard;
import com.ruoyi.web.mapper.GrCardMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@Service
public class GrCardServiceImpl implements IGrCardService {
    @Resource
    private GrCardMapper grCardMapper;

    public List<GrCard> selectGrCardList(GrCard grCard) {
        return grCardMapper.selectGrCardList(grCard);
    }

    @Override
    public int updateGrCard(GrCard grCard) {
        GrCard exist = grCardMapper.selectGrCardById(grCard.getId());
        if(Objects.isNull(exist)){
            throw new RuntimeException("卡不存在 无法更新");
        }
        exist.setAmount(grCard.getAmount());
        return grCardMapper.updateGrCard(exist);
    }

    @Override
    public GrCard selectCardById(Integer cardId) {
        return grCardMapper.selectGrCardById(cardId);
    }
}
